package com.example.controller;

import cn.hutool.json.JSONUtil;
import com.example.anno.CheckName;
import com.example.anno.CheckSqlInjection;
import com.example.entity.dto.CourseDTO;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController()
@RequestMapping("/validate")
public class ValidationController {

    /**
     * 测试自定义校验注解
     */
    @PostMapping("/customValid")
    public CourseDTO validateDemo(@Valid @RequestBody CourseDTO dto) {
        return dto;
    }

    @PostMapping("/checkDemo")
    @CheckSqlInjection
    public String checkDemo(@RequestParam("token") String token, @Valid @RequestBody @CheckName CourseDTO dto) {
        return token + "\n" + JSONUtil.toJsonStr(dto);
    }


}
